import * as types from "./type";
import Http from '@/util/http';
import {fromJS} from "immutable";
import {errorMsg} from "@/util/global";
export const headerTopVisible = (value) => ({
    type: types.HEADER_TOP_VISIBLE,
    value: !!value
})
export const headerSearchInput = (value) => ({
    type: types.HEADER_SEARCH_INPUT,
    value
})
export const headerSearchFocused = (value) => ({
    type: types.HEADER_SEARCH_FOCUS,
    value
})
export const headerTopSearchFocused = (value) => ({
    type: types.HEADER_TOP_SEARCH_FOCUSED,
    value
})
export const headerSearchInit = () => {
    return (dispatch) => {
        try {
            Http.get('/sys/area/province').then((res) => {
                let value = () => {
                    let result = [];
                    for (let i in res.data) {
                        result.push(res.data[i].name);
                    }
                    return result;
                }
                dispatch({type: types.HEADER_SEARCH_INIT, value: fromJS(value())})
            }).catch((e) => {
                errorMsg('网络异常！请先检查网络！')
                console.log(e);
            })
        } catch (e) {
            console.log(e);
        }
    }
}
